#ifndef _BACKDROP_H_
#define _BACKDROP_H_

#include <string>
#include "math/vec2.h"
#include "ui/ui_sprite.h"
#include "input/mouse.h"
#include "input/keyboard.h"
#include "util/ticker.h"
#include "script/scripthelper.h"
#include "script/write_lua.h"

namespace camera
{
	class FbCamera;
}
namespace LuaPlus
{
	class LuaState;
};

namespace backdrop
{
class Decal;
class BackdropEditor;
class BackdropSFX;
class TransientBackdrop;
class TransientDecal;

class Backdrop
{
public:
	Backdrop(camera::FbCamera* pCam);
	virtual ~Backdrop();

	virtual void					SetBackgroundImg(const std::string& File);
	virtual void					AddDecalSprite(Decal* pDecal);
	virtual Decal*					CreateDecalSprite(const std::string& File,
													  const math::Vec2& pos,
													  const math::Vec2& size = math::Vec2(0.0f, 0.0f)) = 0;

	virtual Decal*					GetDecalSprite(const math::Vec2& Pos);
	virtual bool					DeleteDecalSprite(Decal* pDecal);
	virtual void					ResetDecalPos();

	void							AddTransientSprite(const std::string& File,
													   const math::Vec2& pos,
													   const math::Vec2& dir,
													   int Layer = 0);
	TransientDecal*					GetTransientSprite(const math::Vec2& Pos);
	void							DeleteTransientSprite(TransientDecal* pDecal, bool bDelete = true);

	void							Render();
	virtual void					PreRender();
	virtual void					PostRender();
	virtual void					Tick(float dt);
	virtual void					Clear();
	virtual void					ClearLevel();

	virtual bool					LoadBackdrop(const std::string& File);
	virtual bool					SaveBackdrop(const std::string& File);
	virtual void					SaveSpecial(script::WriteLua& Output) {}
	virtual void					LoadSpecial(LuaPlus::LuaState* pScript) {}

	virtual	void					MouseButtonPressed(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos) {}
	virtual void					MouseMove(const math::Vec2& From, const math::Vec2& To) {}
	virtual void					MouseButtonDown(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos) {}
	virtual void					MouseButtonReleased(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos) {}
	virtual void					MouseWheelMove(int WheelInfo, const math::Vec2& Pos) {}
	virtual void					KeyPressed(input::Keyboard::KEY* pKey) {}

	camera::FbCamera*				GetCamera() const { return m_pCamera; }
	BackdropEditor*					GetEditor() const { return m_pEditor; }
	BackdropSFX*					GetSFX() const { return m_pSFX; }
	const std::string&				GetFileName() { return m_Filename; }
	const math::Vec2&				GetOffset() { return m_Offset; }

	virtual float					GetExtentW() const { return 1.0f; }
	virtual float					GetExtentH() const { return 1.0f; }
	virtual bool					UseTransient() const { return m_pTransient ? true : false; }

protected:
	camera::FbCamera*				m_pCamera;
	BackdropEditor*					m_pEditor;
	BackdropSFX*					m_pSFX;
	TransientBackdrop*				m_pTransient;

	ui::UISprite					m_BackgroundImg;
	std::vector<Decal*>				m_BackDecals;
	std::vector<Decal*>				m_ForeDecals;

	math::Vec2						m_Offset;
	math::Vec2						m_WindSpeed;
	math::Vec2						m_Gravity;

private:
	std::string						m_Filename;
};
}

#endif // _BACKDROP_H_